package es.arcadio {
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	import mx.states.State;
	import mx.validators.CurrencyValidatorAlignSymbol;
	
	import spark.components.Button;
	import spark.components.ToggleButton;
	import spark.components.supportClasses.Skin;

	public class Day extends ToggleButton {
		//public var dayData:CalendarioEvent;
		public var isToday:Boolean = false;
		public var events:ArrayCollection;
		public var number:int;
		public var dayDate:Date;

		public function Day() {
			super();
			this.styleName = "buttonCalendar";
			this.setStyle("skinClass", CalendarioToggleButtonSkin);
			this.percentWidth=100;
			this.percentHeight=100;
			
			events = new ArrayCollection();
		}
		
		public function setTodayStyle():void {
			this.styleName += " todayButtonCalendar";
			isToday=true;
		}
		
		public function setPreviousTodayStyle():void {
			this.styleName += " previousTodayButtonCalendar";
			this.setStyle("skinClass", CalendarioPreviousDaysToggleButtonSkin);
		}
		
		/*
		public function setEvent(event:CalendarioEvent):void {
			this.styleName = "eventButtonCalendar";
			
			//this.dayData=event as CalendarioEvent;
			this.toolTip= events.toString();
		}
		*/
		
		public function addEvent(event:CalendarioEvent):void {
			if (events.length == 0 ) {
				this.styleName += " eventButtonCalendar";
				this.invalidateDisplayList();
			}
			events.addItem(event);
			this.toolTip = events.toString();
		}
		
		override protected function getCurrentSkinState():String {
			if (isToday == true) {
				if (selected && super.getCurrentSkinState() != "overAndSelected") {
					return "todayDown";
				} else {
					if (super.getCurrentSkinState() == "over" 
						|| super.getCurrentSkinState() == "overAndSelected") {
						return super.getCurrentSkinState();
					} else {
						return "todayUp";
					}
				}
			} else {
				return super.getCurrentSkinState();
			}
		}
		
		public function getEventsLabel ():String {
			var result:String = "";
			var index:int;
			for each (var event:CalendarioEvent in events) {
				result += event.title;
				index++;
				if(index < events.length) {
					result += "\n - ";
				}
			}
			return result;
		}
	}
}